package Views;

import Controllers.KitchenCTR;
import Controllers.ItemCTR;
import Models.Item;
import Models.Kitchen;
import Models.KitchenPartType;
import Views.TableModels.ItemTableModel;
import Views.TableModels.KitchenTableModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * @author Thomas og Morten
 */
public class KitchenView extends javax.swing.JFrame implements ListSelectionListener, WindowListener
{
	private Item tableTopTemp = null, searchItem = null;
	private ArrayList<Item> cupboardsTemp = new ArrayList<Item>(),
							drawersTemp = new ArrayList<Item>(),
							appliancesTemp = new ArrayList<Item>();
	private ItemPicker ip = null;
	private KitchenCTR controller = new KitchenCTR();

    public KitchenView()
	{
		initComponents();
		addCupBoardsTable.getSelectionModel().addListSelectionListener(this);
		addDrawersTable.getSelectionModel().addListSelectionListener(this);
		addAppliancesTable.getSelectionModel().addListSelectionListener(this);
		findTable.addMouseListener(new MouseAdapter(){
			@Override
			public void mouseClicked(MouseEvent e){
				if (e.getClickCount() == 2)
				{
					if(findTable.getSelectedRowCount() == 1)
					{
						int chosenId = Integer.parseInt(findTable.getValueAt(findTable.getSelectedRow(), 0).toString());
						new KitchenInfoView(controller.getKitchen(chosenId)).setVisible(true);
					}
				}
			}
		 });
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        addKitchen = new javax.swing.JPanel();
        addDescription = new javax.swing.JLabel();
        addNameLabel = new javax.swing.JLabel();
        addNameTF = new javax.swing.JTextField();
        addTableTopLabel = new javax.swing.JLabel();
        addTableTopTF = new javax.swing.JTextField();
        addTableTopButton = new javax.swing.JButton();
        addCupBoardsLabel = new javax.swing.JLabel();
        cupBoardsScrollPane = new javax.swing.JScrollPane();
        addCupBoardsTable = new javax.swing.JTable();
        addCupBoardsButton = new javax.swing.JButton();
        removeCupBoardsButton = new javax.swing.JButton();
        addDrawersLabel = new javax.swing.JLabel();
        addDrawersScrollPanel = new javax.swing.JScrollPane();
        addDrawersTable = new javax.swing.JTable();
        addDrawersButton = new javax.swing.JButton();
        removeDrawersButton = new javax.swing.JButton();
        addAppliancesLabel = new javax.swing.JLabel();
        addAppliancesScrollPanel = new javax.swing.JScrollPane();
        addAppliancesTable = new javax.swing.JTable();
        addAppliancesButton = new javax.swing.JButton();
        removeAppliancesButton = new javax.swing.JButton();
        addPriceLabel = new javax.swing.JLabel();
        addPriceSP = new javax.swing.JSpinner();
        addAddButton = new javax.swing.JButton();
        addPriceLabel1 = new javax.swing.JLabel();
        findKitchen = new javax.swing.JPanel();
        findDescriptionLabel = new javax.swing.JLabel();
        findNameLabel = new javax.swing.JLabel();
        findItemLabel = new javax.swing.JLabel();
        findNameTF = new javax.swing.JTextField();
        findItemTF = new javax.swing.JTextField();
        findPriceLabel = new javax.swing.JLabel();
        findPriceSP = new javax.swing.JSpinner();
        findFindButton = new javax.swing.JButton();
        findScrollPane = new javax.swing.JScrollPane();
        findTable = new javax.swing.JTable();
        findPriceLabel1 = new javax.swing.JLabel();
        findItemButton = new javax.swing.JButton();
        findShowAllButton = new javax.swing.JButton();
        getKitchen = new javax.swing.JPanel();
        getDescriptionLabel = new javax.swing.JLabel();
        getIdLabel = new javax.swing.JLabel();
        getIdSP = new javax.swing.JSpinner();
        getIdButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Køkkener");

        addDescription.setText("Her kan der tilføjes dele til et køkken");

        addNameLabel.setText("Navn:");

        addTableTopLabel.setText("Bordplade:");

        addTableTopButton.setText("Find");
        addTableTopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTableTopButtonActionPerformed(evt);
            }
        });

        addCupBoardsLabel.setText("Skabe:");

        addCupBoardsTable.setModel(new ItemTableModel(this.cupboardsTemp));
        cupBoardsScrollPane.setViewportView(addCupBoardsTable);

        addCupBoardsButton.setText("Tilføj");
        addCupBoardsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCupBoardsButtonActionPerformed(evt);
            }
        });

        removeCupBoardsButton.setText("Fjern");
        removeCupBoardsButton.setEnabled(false);
        removeCupBoardsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeCupBoardsButtonActionPerformed(evt);
            }
        });

        addDrawersLabel.setText("Skuffer:");

        addDrawersTable.setModel(new ItemTableModel(this.drawersTemp));
        addDrawersScrollPanel.setViewportView(addDrawersTable);

        addDrawersButton.setText("Tilføj");
        addDrawersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDrawersButtonActionPerformed(evt);
            }
        });

        removeDrawersButton.setText("Fjern");
        removeDrawersButton.setEnabled(false);
        removeDrawersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeDrawersButtonActionPerformed(evt);
            }
        });

        addAppliancesLabel.setText("Tilbehør:");

        addAppliancesTable.setModel(new ItemTableModel(this.appliancesTemp));
        addAppliancesScrollPanel.setViewportView(addAppliancesTable);

        addAppliancesButton.setText("Tilføj");
        addAppliancesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addAppliancesButtonActionPerformed(evt);
            }
        });

        removeAppliancesButton.setText("Fjern");
        removeAppliancesButton.setEnabled(false);
        removeAppliancesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeAppliancesButtonActionPerformed(evt);
            }
        });

        addPriceLabel.setText("Pris:");

        addAddButton.setText("Tilføj");
        addAddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addAddButtonActionPerformed(evt);
            }
        });

        addPriceLabel1.setText("kr.");

        org.jdesktop.layout.GroupLayout addKitchenLayout = new org.jdesktop.layout.GroupLayout(addKitchen);
        addKitchen.setLayout(addKitchenLayout);
        addKitchenLayout.setHorizontalGroup(
            addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(addKitchenLayout.createSequentialGroup()
                .addContainerGap()
                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(addKitchenLayout.createSequentialGroup()
                        .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(addKitchenLayout.createSequentialGroup()
                                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(addKitchenLayout.createSequentialGroup()
                                        .add(addNameLabel)
                                        .add(40, 40, 40))
                                    .add(addKitchenLayout.createSequentialGroup()
                                        .add(addTableTopLabel)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(addNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(addKitchenLayout.createSequentialGroup()
                                        .add(addTableTopTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(addTableTopButton))))
                            .add(addDescription))
                        .add(268, 268, 268))
                    .add(addKitchenLayout.createSequentialGroup()
                        .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(addCupBoardsLabel)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, addKitchenLayout.createSequentialGroup()
                                .add(cupBoardsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 315, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(removeCupBoardsButton)
                                    .add(addCupBoardsButton))))
                        .add(127, 127, 127))
                    .add(addKitchenLayout.createSequentialGroup()
                        .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(addDrawersLabel)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, addKitchenLayout.createSequentialGroup()
                                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(addAppliancesScrollPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                                    .add(addDrawersScrollPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(addDrawersButton)
                                    .add(removeDrawersButton)
                                    .add(addAppliancesButton)
                                    .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(addAddButton)
                                        .add(removeAppliancesButton)))
                                .add(86, 86, 86)))
                        .add(39, 39, 39))
                    .add(addKitchenLayout.createSequentialGroup()
                        .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(addAppliancesLabel)
                            .add(addKitchenLayout.createSequentialGroup()
                                .add(addPriceLabel)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(addPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 108, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(addPriceLabel1)))
                        .addContainerGap(190, Short.MAX_VALUE))))
        );
        addKitchenLayout.setVerticalGroup(
            addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(addKitchenLayout.createSequentialGroup()
                .addContainerGap()
                .add(addDescription)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addNameLabel)
                    .add(addNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(addTableTopButton)
                        .add(addTableTopTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(addTableTopLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addCupBoardsLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(addKitchenLayout.createSequentialGroup()
                        .add(addCupBoardsButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeCupBoardsButton))
                    .add(cupBoardsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addDrawersLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(addKitchenLayout.createSequentialGroup()
                        .add(addDrawersButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeDrawersButton))
                    .add(addDrawersScrollPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addAppliancesLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(addKitchenLayout.createSequentialGroup()
                        .add(addAppliancesButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeAppliancesButton))
                    .add(addAppliancesScrollPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(addPriceLabel)
                    .add(addPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addPriceLabel1))
                .add(28, 28, 28)
                .add(addAddButton)
                .add(109, 109, 109))
        );

        jTabbedPane1.addTab("Tilføj", addKitchen);

        findDescriptionLabel.setText("Her kan der søges på et køkken");

        findNameLabel.setText("Navn:");

        findItemLabel.setText("Vare:");

        findPriceLabel.setText("Pris:");

        findFindButton.setText("Søg");
        findFindButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findFindButtonActionPerformed(evt);
            }
        });

        findTable.setModel(new KitchenTableModel());
        findScrollPane.setViewportView(findTable);

        findPriceLabel1.setText("kr.");

        findItemButton.setText("Find");
        findItemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findItemButtonActionPerformed(evt);
            }
        });

        findShowAllButton.setText("Vis alle");
        findShowAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findShowAllButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout findKitchenLayout = new org.jdesktop.layout.GroupLayout(findKitchen);
        findKitchen.setLayout(findKitchenLayout);
        findKitchenLayout.setHorizontalGroup(
            findKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(findKitchenLayout.createSequentialGroup()
                .addContainerGap()
                .add(findKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, findScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
                    .add(findDescriptionLabel)
                    .add(findKitchenLayout.createSequentialGroup()
                        .add(findFindButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(findShowAllButton))
                    .add(findKitchenLayout.createSequentialGroup()
                        .add(findPriceLabel)
                        .add(18, 18, 18)
                        .add(findPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(findPriceLabel1))
                    .add(findKitchenLayout.createSequentialGroup()
                        .add(findKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, findKitchenLayout.createSequentialGroup()
                                .add(findItemLabel)
                                .add(13, 13, 13)
                                .add(findItemTF))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, findKitchenLayout.createSequentialGroup()
                                .add(findNameLabel)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(findNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 133, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(findItemButton)))
                .addContainerGap())
        );
        findKitchenLayout.setVerticalGroup(
            findKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(findKitchenLayout.createSequentialGroup()
                .addContainerGap()
                .add(findDescriptionLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(findKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findNameLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(findKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findItemTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findItemLabel)
                    .add(findItemButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(findKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(findPriceLabel)
                    .add(findPriceLabel1))
                .add(18, 18, 18)
                .add(findKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(findFindButton)
                    .add(findShowAllButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(findScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(118, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Søg", findKitchen);

        getDescriptionLabel.setText("Her kan der søges på et køkkens ID");

        getIdLabel.setText("ID:");

        getIdButton.setText("Hent");
        getIdButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getIdButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout getKitchenLayout = new org.jdesktop.layout.GroupLayout(getKitchen);
        getKitchen.setLayout(getKitchenLayout);
        getKitchenLayout.setHorizontalGroup(
            getKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(getKitchenLayout.createSequentialGroup()
                .addContainerGap()
                .add(getKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(getDescriptionLabel)
                    .add(getKitchenLayout.createSequentialGroup()
                        .add(getIdLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(getIdSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(getIdButton))
                .addContainerGap(141, Short.MAX_VALUE))
        );
        getKitchenLayout.setVerticalGroup(
            getKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(getKitchenLayout.createSequentialGroup()
                .addContainerGap()
                .add(getDescriptionLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(getKitchenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(getIdLabel)
                    .add(getIdSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(getIdButton)
                .addContainerGap(400, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Hent", getKitchen);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void findFindButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findFindButtonActionPerformed
		findTable.setModel(
				new KitchenTableModel(
					this.controller.findKitchen(findNameTF.getText(),Double.parseDouble(findPriceSP.getValue().toString()), null, null, null, null, searchItem)));
}//GEN-LAST:event_findFindButtonActionPerformed

	private void addTableTopButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addTableTopButtonActionPerformed
	{//GEN-HEADEREND:event_addTableTopButtonActionPerformed
		ip = new ItemPicker();
		ip.addWindowListener(this);
		ip.setVisible(true);
	}//GEN-LAST:event_addTableTopButtonActionPerformed

	private void addCupBoardsButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addCupBoardsButtonActionPerformed
	{//GEN-HEADEREND:event_addCupBoardsButtonActionPerformed
		ip = new ItemPicker(KitchenPartType.cupBoards);
		ip.addWindowListener(this);
		ip.setVisible(true);
	}//GEN-LAST:event_addCupBoardsButtonActionPerformed

	private void removeCupBoardsButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_removeCupBoardsButtonActionPerformed
	{//GEN-HEADEREND:event_removeCupBoardsButtonActionPerformed
		int chosenId = Integer.parseInt(addCupBoardsTable.getValueAt(addCupBoardsTable.getSelectedRow(), 0).toString());
		ItemCTR stockController = new ItemCTR();
		this.cupboardsTemp.remove(stockController.getItem(chosenId));
	}//GEN-LAST:event_removeCupBoardsButtonActionPerformed

	private void addDrawersButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addDrawersButtonActionPerformed
	{//GEN-HEADEREND:event_addDrawersButtonActionPerformed
		ip = new ItemPicker(KitchenPartType.drawers);
		ip.addWindowListener(this);
		ip.setVisible(true);
	}//GEN-LAST:event_addDrawersButtonActionPerformed

	private void removeDrawersButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_removeDrawersButtonActionPerformed
	{//GEN-HEADEREND:event_removeDrawersButtonActionPerformed
		int chosenId = Integer.parseInt(addDrawersTable.getValueAt(addDrawersTable.getSelectedRow(), 0).toString());
		ItemCTR stockController = new ItemCTR();
		this.drawersTemp.remove(stockController.getItem(chosenId));
	}//GEN-LAST:event_removeDrawersButtonActionPerformed

	private void addAppliancesButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addAppliancesButtonActionPerformed
	{//GEN-HEADEREND:event_addAppliancesButtonActionPerformed
		ip = new ItemPicker(KitchenPartType.appliances);
		ip.addWindowListener(this);
		ip.setVisible(true);
	}//GEN-LAST:event_addAppliancesButtonActionPerformed

	private void removeAppliancesButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_removeAppliancesButtonActionPerformed
	{//GEN-HEADEREND:event_removeAppliancesButtonActionPerformed
		int chosenId = Integer.parseInt(addAppliancesTable.getValueAt(addAppliancesTable.getSelectedRow(), 0).toString());
		ItemCTR stockController = new ItemCTR();
		this.appliancesTemp.remove(stockController.getItem(chosenId));
	}//GEN-LAST:event_removeAppliancesButtonActionPerformed

	private void addAddButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addAddButtonActionPerformed
	{//GEN-HEADEREND:event_addAddButtonActionPerformed
		if(addNameTF.getText().equals(""))
		{
			this.controller.addItem(addNameTF.getText(), Double.parseDouble(addPriceSP.getValue().toString()), tableTopTemp, cupboardsTemp, drawersTemp, appliancesTemp);
			JOptionPane.showMessageDialog(this, "Køkkenet '"+addNameTF.getText()+"' er tilføjet til kataloget.", "Køkkenet er tilføjet", JOptionPane.INFORMATION_MESSAGE);
		}
	}//GEN-LAST:event_addAddButtonActionPerformed

	private void findItemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findItemButtonActionPerformed
		ip = new ItemPicker();
		ip.addWindowListener(this);
		ip.setVisible(true);
}//GEN-LAST:event_findItemButtonActionPerformed

	private void getIdButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_getIdButtonActionPerformed
	{//GEN-HEADEREND:event_getIdButtonActionPerformed
		Kitchen kitchen = this.controller.getKitchen(Integer.parseInt(getIdSP.getValue().toString()));
		if(kitchen != null)
		{
			new KitchenInfoView(kitchen).setVisible(true);
		}
		else
		{
			JOptionPane.showMessageDialog(this, "Der er angivet et forkert ID.", "Forkert ID", JOptionPane.ERROR_MESSAGE);
		}
	}//GEN-LAST:event_getIdButtonActionPerformed

	private void findShowAllButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_findShowAllButtonActionPerformed
	{//GEN-HEADEREND:event_findShowAllButtonActionPerformed
		findTable.setModel(new KitchenTableModel(this.controller.getAllKitchens()));
	}//GEN-LAST:event_findShowAllButtonActionPerformed

	public void valueChanged(ListSelectionEvent e)
	{
		if(((JTable)e.getSource()).getSelectedRowCount() == 1)
		{
			if(e.getSource() == addCupBoardsTable)
			{
				removeCupBoardsButton.setEnabled(true);
			}
			else if(e.getSource() == addDrawersTable)
			{
				removeDrawersButton.setEnabled(true);
			}
			else if(e.getSource() == addAppliancesTable)
			{
				removeAppliancesButton.setEnabled(true);
			}
		}
		else
		{
			if(e.getSource() == addCupBoardsTable)
			{
				removeCupBoardsButton.setEnabled(false);
			}
			else if(e.getSource() == addDrawersTable)
			{
				removeDrawersButton.setEnabled(false);
			}
			else if(e.getSource() == addAppliancesTable)
			{
				removeAppliancesButton.setEnabled(false);
			}
		}
	}

	public void windowClosing(WindowEvent e)
	{
		if(ip != null)
		{
			KitchenPartType partType = ip.getPartType();
			if(partType.equals(KitchenPartType.tableTop))
			{
				this.tableTopTemp = ip.getChosenItem();
			}
			else if(partType.equals(KitchenPartType.cupBoards))
			{
				this.cupboardsTemp.add(ip.getChosenItem());
			}
			else if(partType.equals(KitchenPartType.drawers))
			{
				this.drawersTemp.add(ip.getChosenItem());
			}
			else if(partType.equals(KitchenPartType.appliances))
			{
				this.appliancesTemp.add(ip.getChosenItem());
			}
			else
			{
				this.searchItem = ip.getChosenItem();
				findItemTF.setText(this.searchItem.getName());
			}
		}
	}

	public void windowOpened(WindowEvent e) {}
	public void windowClosed(WindowEvent e) {}
	public void windowIconified(WindowEvent e) {}
	public void windowDeiconified(WindowEvent e) {}
	public void windowActivated(WindowEvent e) {}
	public void windowDeactivated(WindowEvent e) {}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addAddButton;
    private javax.swing.JButton addAppliancesButton;
    private javax.swing.JLabel addAppliancesLabel;
    private javax.swing.JScrollPane addAppliancesScrollPanel;
    private javax.swing.JTable addAppliancesTable;
    private javax.swing.JButton addCupBoardsButton;
    private javax.swing.JLabel addCupBoardsLabel;
    private javax.swing.JTable addCupBoardsTable;
    private javax.swing.JLabel addDescription;
    private javax.swing.JButton addDrawersButton;
    private javax.swing.JLabel addDrawersLabel;
    private javax.swing.JScrollPane addDrawersScrollPanel;
    private javax.swing.JTable addDrawersTable;
    private javax.swing.JPanel addKitchen;
    private javax.swing.JLabel addNameLabel;
    private javax.swing.JTextField addNameTF;
    private javax.swing.JLabel addPriceLabel;
    private javax.swing.JLabel addPriceLabel1;
    private javax.swing.JSpinner addPriceSP;
    private javax.swing.JButton addTableTopButton;
    private javax.swing.JLabel addTableTopLabel;
    private javax.swing.JTextField addTableTopTF;
    private javax.swing.JScrollPane cupBoardsScrollPane;
    private javax.swing.JLabel findDescriptionLabel;
    private javax.swing.JButton findFindButton;
    private javax.swing.JButton findItemButton;
    private javax.swing.JLabel findItemLabel;
    private javax.swing.JTextField findItemTF;
    private javax.swing.JPanel findKitchen;
    private javax.swing.JLabel findNameLabel;
    private javax.swing.JTextField findNameTF;
    private javax.swing.JLabel findPriceLabel;
    private javax.swing.JLabel findPriceLabel1;
    private javax.swing.JSpinner findPriceSP;
    private javax.swing.JScrollPane findScrollPane;
    private javax.swing.JButton findShowAllButton;
    private javax.swing.JTable findTable;
    private javax.swing.JLabel getDescriptionLabel;
    private javax.swing.JButton getIdButton;
    private javax.swing.JLabel getIdLabel;
    private javax.swing.JSpinner getIdSP;
    private javax.swing.JPanel getKitchen;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton removeAppliancesButton;
    private javax.swing.JButton removeCupBoardsButton;
    private javax.swing.JButton removeDrawersButton;
    // End of variables declaration//GEN-END:variables
}